import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout/index.vue";

export const constantRoutes = [
  {
    path: "/login",
    component: () => import("@/views/login/index.vue"),
  },
  {
    path: "/",
    redirect: "/file",
  },
  {
    path: "/file",
    name: "file",
    redirect: "/file/backups",
    component: Layout,
    children: [
      {
        path: "backups",
        name: "backups",
        component: () => import("@/views/file/backups.vue"),
      },
      {
        path: "resource",
        name: "resource",
        component: () => import("@/views/file/resource.vue"),
      },
    ],
  },
  {
    path: "/picture",
    name: "picture",
    redirect: "/picture/all",
    component: Layout,
    children: [
      {
        path: "mine",
        name: "mine",
        component: () => import("@/views/picture/mine.vue"),
      },
      {
        path: "all",
        name: "all",
        component: () => import("@/views/picture/all.vue"),
      },
    ],
  },
  {
    path: "/app",
    name: "app",
    redirect: "/app/bin",
    component: Layout,
    children: [
      {
        path: "bin",
        name: "bin",
        component: () => import("@/views/app/bin.vue"),
      },
      {
        path: "lockbox",
        name: "lockbox",
        component: () => import("@/views/app/lockbox.vue"),
      },
      {
        path: "share",
        name: "share",
        component: () => import("@/views/app/share.vue"),
      },
      {
        path: "quick",
        name: "quick",
        component: () => import("@/views/app/quick.vue"),
      },
      {
        path: "collection",
        name: "collection",
        component: () => import("@/views/app/collection.vue"),
      },
      {
        path: "subscription",
        name: "subscription",
        component: () => import("@/views/app/subscription.vue"),
      },
      {
        path: "scanning",
        name: "scanning",
        component: () => import("@/views/app/scanning.vue"),
      },
      {
        path: "printing",
        name: "printing",
        component: () => import("@/views/app/printing.vue"),
      },
      {
        path: "application",
        name: "application",
        component: () => import("@/views/app/application.vue"),
      },
    ],
  },
  {
    path: "/mine",
    name: "mine",
    component: Layout,
    children: [
      {
        path: "mine",
        name: "mine",
        component: () => import("@/views/mine/mine.vue")
      }
    ]
  },
  {
    path: "/announce",
    name: "announce",
    component: Layout,
    children: [
      {
        path: "announce",
        name: "announce",
        component: () => import("@/views/announce/announce")
      }
    ]
  },
  {
    path: "/AIMessage",
    name: "AIMessage",
    component: Layout,
    children: [
      {
        path: "AI",
        name: "AI",
        component: () => import("@/views/AIMessage/AIMessage")
      }
    ]
  },
];

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({y: 0}),
    routes: constantRoutes,
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
